package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/changdu/config"
	"net/http"
	"net/url"
)

type PromotionListV1ApiService service

type PromotionListV1GetRequest struct {
	ctx              context.Context
	ApiService       *PromotionListV1ApiService
	distributorId    *uint64
	bookId           *string
	promotionId      *string
	begin            *uint64
	end              *uint64
	offset           *uint32
	limit            *uint32
	optimizerAccount *string
	optimizerId      *uint64
}

type PromotionListV1GetResponse struct {
	Code       *int64                      `json:"code,omitempty"`
	Message    *string                     `json:"message,omitempty"`
	HasMore    *bool                       `json:"has_more,omitempty"`
	NextOffset *uint64                     `json:"next_offset,omitempty"`
	Result     []*PromotionListV1GetResult `json:"result,omitempty"`
}

type PromotionListV1GetResult struct {
	AdCallbackConfigId *int    `json:"ad_callback_config_id,omitempty"`
	BookId             *int64  `json:"book_id,omitempty"`
	BookName           *string `json:"book_name,omitempty"`
	ChapterId          *int64  `json:"chapter_id,omitempty"`
	ChapterOrder       *int64  `json:"chapter_order,omitempty"`
	ChapterTitle       *string `json:"chapter_title,omitempty"`
	CreateTime         *string `json:"create_time,omitempty"`
	MediaSource        *int    `json:"media_source,omitempty"`
	MonitorUrl         *string `json:"monitor_url,omitempty"`
	OptimizerAccount   *string `json:"optimizer_account,omitempty"`
	OptimizerId        *uint64 `json:"optimizer_id,omitempty"`
	PackStrategyStatus *int64  `json:"pack_strategy_status,omitempty"`
	PermissionStatus   *int64  `json:"permission_status,omitempty"`
	PromotionId        *uint64 `json:"promotion_id,omitempty"`
	PromotionName      *string `json:"promotion_name,omitempty"`
	PromotionUrl       *string `json:"promotion_url,omitempty"`
}

func (r *PromotionListV1GetRequest) DistributorId(distributorId uint64) *PromotionListV1GetRequest {
	r.distributorId = &distributorId
	return r
}

func (r *PromotionListV1GetRequest) BookId(bookId string) *PromotionListV1GetRequest {
	r.bookId = &bookId
	return r
}

func (r *PromotionListV1GetRequest) PromotionId(promotionId string) *PromotionListV1GetRequest {
	r.promotionId = &promotionId
	return r
}

func (r *PromotionListV1GetRequest) Begin(begin uint64) *PromotionListV1GetRequest {
	r.begin = &begin
	return r
}

func (r *PromotionListV1GetRequest) End(end uint64) *PromotionListV1GetRequest {
	r.end = &end
	return r
}

func (r *PromotionListV1GetRequest) Offset(offset uint32) *PromotionListV1GetRequest {
	r.offset = &offset
	return r
}

func (r *PromotionListV1GetRequest) Limit(limit uint32) *PromotionListV1GetRequest {
	r.limit = &limit
	return r
}

func (r *PromotionListV1GetRequest) OptimizerAccount(optimizerAccount string) *PromotionListV1GetRequest {
	r.optimizerAccount = &optimizerAccount
	return r
}

func (r *PromotionListV1GetRequest) OptimizerId(optimizerId uint64) *PromotionListV1GetRequest {
	r.optimizerId = &optimizerId
	return r
}

func (r *PromotionListV1GetRequest) Execute() (*PromotionListV1GetResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *PromotionListV1GetRequest) SecretKey(SecretKey string) *PromotionListV1GetRequest {
	r.ctx = context.WithValue(r.ctx, config.SecretKey, SecretKey)
	return r
}

func (r *PromotionListV1GetRequest) WithLog(enable bool) *PromotionListV1GetRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *PromotionListV1ApiService) Get(ctx context.Context) *PromotionListV1GetRequest {
	return &PromotionListV1GetRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *PromotionListV1ApiService) getExecute(r *PromotionListV1GetRequest) (*PromotionListV1GetResponse, *http.Response, error) {
	var (
		localVarPath         = a.client.Cfg.GetBasePath() + "/novelsale/openapi/promotion/list/v1"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *PromotionListV1GetResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasReqParam(r.distributorId, "DistributorId"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}
	localVarQueryParams.Add("distributor_id", toString(r.distributorId))

	if r.bookId != nil {
		localVarQueryParams.Add("book_id", toString(r.bookId))
	}
	if r.promotionId != nil {
		localVarQueryParams.Add("promotion_id", toString(r.promotionId))
	}
	if r.begin != nil {
		localVarQueryParams.Add("begin", toString(r.begin))
	}
	if r.end != nil {
		localVarQueryParams.Add("end", toString(r.end))
	}
	if r.offset != nil {
		localVarQueryParams.Add("offset", toString(r.offset))
	}
	if r.limit != nil {
		localVarQueryParams.Add("limit", toString(r.limit))
	}
	if r.optimizerAccount != nil {
		localVarQueryParams.Add("optimizer_account", toString(r.optimizerAccount))
	}
	if r.optimizerId != nil {
		localVarQueryParams.Add("optimizer_id", toString(r.optimizerId))
	}

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
